package com.example.my.meila.view.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.my.meila.R;
import com.example.my.meila.common.image.ImageLoader;
import com.example.my.meila.constast.Constast;
import com.example.my.meila.entity.Paihangbang;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhanghao on 2016/10/31.
 */
public class PaihangbangTopAdapter extends RecyclerView.Adapter<PaihangbangTopAdapter.MainViewholder> {


    private Context context;
    private List<Paihangbang.DataBean.NationsBean.ProductsBean> data;

    public PaihangbangTopAdapter(Context context, List<Paihangbang.DataBean.NationsBean.ProductsBean> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public MainViewholder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View view = inflater.inflate(R.layout.item_recyclerview_paihangbang_top, null);
        MainViewholder holder = new MainViewholder(view);
        return holder;
    }


    @Override
    public void onBindViewHolder(MainViewholder holder, int position) {
        switch (position){
            case 0:
                holder.ivPaihangbangNumber.setImageResource(R.mipmap.icon_top_red_01);
                break;
            case 1:
                holder.ivPaihangbangNumber.setImageResource(R.mipmap.icon_top_red_01);
                break;
            case 2:
                holder.ivPaihangbangNumber.setImageResource(R.mipmap.icon_top_red_02);
                break;
            case 3:
                holder.ivPaihangbangNumber.setImageResource(R.mipmap.icon_top_red_03);
                break;
            case 4:
                holder.ivPaihangbangNumber.setImageResource(R.mipmap.icon_top_red_04);
                break;
            case 5:
                holder.ivPaihangbangNumber.setImageResource(R.mipmap.icon_top_red_05);
                break;
            case 6:
                holder.ivPaihangbangNumber.setImageResource(R.mipmap.icon_top_red_06);
                break;
            case 7:
                holder.ivPaihangbangNumber.setImageResource(R.mipmap.icon_top_red_07);
                break;
            case 8:
                holder.ivPaihangbangNumber.setImageResource(R.mipmap.icon_top_red_08);
                break;
            case 9:
                holder.ivPaihangbangNumber.setImageResource(R.mipmap.icon_top_red_09);
                break;
        }
        holder.tvPaihangbangShortName.setText(data.get(position).getShort_name());
        ImageLoader.getInstance().display(context, Constast.PUBLIC_URL + data.get(position).getBanner_thumb(), holder.ivPaihangbangTopimg);

    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class MainViewholder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_paihangbang_topimg)
        ImageView ivPaihangbangTopimg;
        @BindView(R.id.iv_paihangbang_number)
        ImageView ivPaihangbangNumber;
        @BindView(R.id.tv_paihangbang_short_name)
        TextView tvPaihangbangShortName;

        public MainViewholder(View itemView) {

            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
